        .data
        .text
        .global start

init:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]
        str w1, [x29, #20]

        ldrsw x0, [x29, #20]
        lsl x0, x0, #2
        bl malloc
        mov x1, x0
        ldr x0, [x29, #24]
        str x1, [x0]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        cmp x0, #0x0
        b.ne init_label1        ; 40070c

        adrp x0, 400000
        add x0, x0, #0xd38
        bl puts

        mov w0, #0x0
        bl exit

        ldr x0, [x29, #24]
        ldr w1, [x29, #20]
        str w1, [x0, #16]

        ldr x0, [x29, #24]
        str wzr, [x0, #12]
        ldr x0, [x29, #24]
        ldr w1, [x0, #12]
        ldr x0, [x29, #24]
        str w1, [x0, #8]

        nop
        ldp x29, x30, [sp], #32
        ret

empty:
        sub sp, sp, #0x10
        str x0, [sp, #8]

        ldr x0, [sp, #8]
        ldr w1, [x0, #8]
        ldr x0, [sp, #8]
        ldr w0, [x0, #12]
        cmp w1, w0
        b.ne empty_lable1       ; 400764

        mov w0, #0x1
        b emtpy_label2          ; 400768

        mov w0, #0x0

        add sp, sp, #0x10
        ret

full:
        sub sp, sp, #0x10
        str x0, [sp, #8]

        ldr x0, [sp, #8]
        ldr w2, [x0, #8]
        ldr x0, [sp, #8]
        ldr w0, [x0, #12]
        add w0, w0, #0x1
        ldr x1, [sp, #8]
        ldr w1, [x1, #16]
        sdiv w3, w0, w1
        mul w1, w3, w1
        sub w0, w0, w1
        cmp w2, w0
        b.ne full_label1        ; 4007b0

        mov w0, #0x1
        b full_label2           ; 4007b4

        mov w0, #0x0

        add sp, sp, #0x10
        ret

enqueue:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]
        str w1, [x29, #20]

        ldr x0, [x29, #24]
        bl full
        cmp w0, #0x0
        b.eq enqueue_label1     ; 4007ec

        adrp x0, 400000
        add x0, x0, #0xd50
        bl puts

        b enqueue_label2        ; 400838

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        sxtw x0, w0
        lsl x0, x0, #2
        add x0, x1, x0
        ldr w1, [x29, #20]
        str w1, [x0]

        ldr x0, [x29, #24]
        ldr w0, [x0, #12]
        add w0, w0, #0x1
        ldr x1, [x29, #24]
        ldr w1, [x1, #16]
        sdiv w2, w0, w1
        mul w1, w2, w1
        sub w1, w0, w1
        ldr x0, [x29, #24]
        str w1, [x0, #12]

        ldp x29, x30, [sp], #32
        ret

dequeue:
        stp x29, x30, [sp, #-32]!
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        bl empty
        cmp w0, #0x0
        b.eq dequeue_lable1     ; 40086c

        adrp x0, 400000
        add x0, x0, #0xd60
        bl puts

        b dequeue_label2        ; 4008b8

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        sxtw x0, w0
        lsl x0, x0, #2
        add x0, x1, x0
        mov w1, 0xffffffff
        str w1, [x0]
        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        add w0, w0, #0x1
        ldr x1, [x29, #24]
        ldr w1, [x1, #16]
        sdiv w2, w0, w1
        mul w1, w2, w1
        sub w1, w0, w1
        ldr x0, [x29, #24]
        str w1, [x0, #8]

        ldp x29, x30, [sp], #32
        ret

display:
        stp x29, x30, [sp, #-48]!
        mov x29, sp
        str x0, [x29, #24]

        adrp x0, 400000
        add x0, x0, #0xd70
        bl printf

        ldr x0, [x29, #24]
        ldr w0, [x0, #8]
        str w0, [x29, #44]
        b display_label1        ; 400918

        ldr x0, [0x29, #24]
        ldr x1, [x0]
        ldrsw x0, [x29, #44]
        lsl x0, x0, #2
        add x0, x1, x0
        ldr w1, [x0]
        adrp x0, 400000
        add x0, x0, #0xd80
        bl printf

        ldr w0, [x29, #44]
        add w0, w0, #0x1
        str w0, [x29, #44]
        ldr x0, [x29, #24]
        ldr w1, [x0, #16]
        ldr w0, [x29, #44]
        cmp w1, w0
        b.gt display_label2     ; 4008e8

        adrp x0, 400000
        add x0, x0, #0xd88
        bl puts

        nop
        ldp x29, x30, [sp], #48
        ret

display_all:
        stp x29, x30, [sp, #-48]
        mov x29, sp
        str x0, [x29, #24]

        adrp x0, 400000
        add x0, x0, 0xd90
        bl printf

        str wzr, [x29, #44]
        b display_all_label2    ; 400994

        ldr x0, [x29, #24]
        ldr x1, [x0]
        ldrsw x0, [x29, #44]
        lsl x0, x0, #2
        add x0, x1, x0
        ldr w1, [x0]
        adrp x0, 400000
        add x0, x0, #0xd80
        bl printf

        ldr w0, [x29, #44]
        add w0, w0, #0x1
        str w0, [x29, #44]
        ldr x0, [x29, #24]
        ldr w1, [x0, #16]
        ldr w0, [x29, #44]
        cmp w1, w0
        b.gt display_all_label2 ; 400964

        adrp x0, 40000
        add x0, x0, #0xd88
        bl puts

        nop
        ldp x29, x30, [sp], #48
        ret

clean:
        stp x29, x30, [sp, #-32]
        mov x29, sp
        str x0, [x29, #24]

        ldr x0, [x29, #24]
        ldr x0, [x0]
        cmp x0, #0x0
        b.eq clean_label1       ; 400a08

        ldr x0, [x29, #24]
        ldr x0, [x0]
        bl free

        ldr x0, [x29, #24]
        str xzr, [x0]

        ldr x0, [x29, #24]
        str wzr, [x0, #8]

        ldr x0, [x29, #24]
        str wzr, [x0, #12]

        ldr x0, [x29, #24]
        str wzr, [x0, #16]

        nop
        ldp x29, x30, [sp], #32
        ret

start:
        stp x29, x30, [sp, #-48]!
        mov x29, sp

        mov w0, #0xa
        str w0, [x29, #44]

        add x0, x29, #0x10
        ldr w1, [x29, #44]
        bl init

        add x0, x29, #0x10
        mov w1, #0x1
        bl enqueue

        add x0, x29, #0x10
        bl display

        add x0, x29, #0x10
        bl clean

        ldp x29, x30, [sp], #48
        ret
